<?php
namespace App\Listener;

use Hyperf\Event\Contract\ListenerInterface;
use Hyperf\Event\Annotation\Listener;

/**
 * @Listener 
 */
class UserMoneyPayListener implements ListenerInterface
{
    public function listen(): array
    {
        return [
            \App\Event\User\CreateEvent::class,
            // 补贴统计
            \App\Event\User\MoneyFullAllEvent::class
        ];
    }
    
    // 用户重置复投金额
    public function process($event)
    {
        // 用户
        $user = $event->user;
        
        // 如果有业绩
        if($user->money_all > 0)
        {
            // 不满足复投
            if(!$event->level->moneyPay($user))
            {
                return;
            }
        }

        // 如果正在复投中，就不重置
        if($user->moneyPayOver())
        {
            $user->moneyPaySet($event->config('money_pay'));
        }
    }
}